﻿if (document.domain.split (".").length > 2)
{
	document.domain = document.domain.substring (document.domain.indexOf (".") + 1);
}


var IsIE = (navigator.appName == 'Microsoft Internet Explorer');


IsNullOrEmpty = function (object) {
	return (typeof (object) == 'undefined' || object == null || $.trim(new String(object)).length == 0);
}


function GenerateGUID() {
	var result, i, j;
	result = '';
	for (j = 0; j < 32; j++) {
		if (j == 8 || j == 12 || j == 16 || j == 20)
			result = result + '-';
		i = Math.floor(Math.random() * 16).toString(16).toUpperCase();
		result = result + i;
	}
	return result;
}


ShowHideByID = function (pID, bool_show) {
	if (bool_show) { return ShowByID(pID); }

	return HideByID(pID);
}


HideShowByID = function (pID) {
	if (IsVisibleByID(pID)) { return HideByID(pID); }

	return ShowByID(pID);
}


ShowByID = function (pID) {
	var element = document.getElementById(pID);

	Show(element);
}


HideByID = function (pID) {
	var element = document.getElementById(pID);

	Hide(element);
}


Hide = function (pElem) {
	if (!IsNull(pElem)) {
		pElem.style.display = 'none';
		pElem.style.visibility = 'hidden';
	}
}


Show = function (pElem, pzIndex) {
	if (!IsNull(pElem)) {
		pElem.style.visibility = 'visible';

		if (pElem.id != DIVCOVERID) {
			if (!IsNull(pzIndex)) {
				pElem.style.zIndex = pzIndex;
			}
			else {
				pElem.style.zIndex = '0';
			}
		}

		if (pElem.tagName == 'DIV') {
			pElem.style.display = 'block';
		}
		else {
			pElem.style.display = '';
		}
	}
}


IsVisibleByID = function (pID) {
	var result = true;

	element = document.getElementById(pID);

	if (IsNull(element)) return false;

	if (typeof (element.style.visibility) != 'undefined') { result = result && (element.style.visibility != 'hidden'); }

	if (typeof (element.style.display) != 'undefined') { result = result && (element.style.display != 'none'); }

	return result;
}


/* Miscelaneos */

RemoveByID = function (pID) {
	var element;
	var parentElement;


	element = document.getElementById(pID);

	if (!IsNull(element)) {
		parentElement = element.parent;

		if (!IsNull(parentElement)) {
			parentElement.removeChild(element);
		}
	}
}


function DisableEnterKey(e) {
	var key;


	if (window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if (key == 13)
		return false;
	else
		return true;
}


/* Cadenas */

String.prototype.format = function () {
	var i = 0;
	var string = (typeof (this) == "function" && !(i++)) ? arguments[0] : this;

	while (i < arguments.length) {
		string = string.replaceAll('\\{' + i + '\\}', arguments[i]);
		i++;
	}

	return string;
}

String.prototype.replaceAll = function (search, replace) {
	var str = this.toString();

	while (str.indexOf(search) != -1)
	{ str = str.replace(search, replace); }

	return str;
}


String.prototype.replaceNotBasicChars = function () {
	var str = this;
	str = str.replaceAll("\xe1", "a").replaceAll("\xe9", "e").replaceAll("\xed", "i").replaceAll("\xf3", "o").replaceAll("\xfa", "u").
		replaceAll("\xc1", "A").replaceAll("\xc9", "E").replaceAll("\xcd", "I").replaceAll("\xd3", "O").replaceAll("\xda", "U").
		replaceAll("\xf1", "n").replaceAll("\xd1", "N").replace(/[^a-zA-Z\n\t\?\!\@\#\.\,\;\: 0-9]+/g, '');
	return str;
}

String.prototype.regexIndexOf = function (regex, startpos) {
	var indexOf = this.substring(startpos || 0).search(regex);
	return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf;
}

String.prototype.regexLastIndexOf = function (regex, startpos) {
	regex = (regex.global) ? regex : new RegExp(regex.source, "g" + (regex.ignoreCase ? "i" : "") + (regex.multiLine ? "m" : ""));
	if (typeof (startpos) == "undefined") {
		startpos = this.length;
	} else if (startpos < 0) {
		startpos = 0;
	}
	var stringToWorkWith = this.substring(0, startpos + 1);
	var lastIndexOf = -1;
	var nextStop = 0;
	while ((result = regex.exec(stringToWorkWith)) != null) {
		lastIndexOf = result.index;
		regex.lastIndex = ++nextStop;
	}
	return lastIndexOf;
}

/* Eventos */

function AddFuncEvent(pElem, pEventBasicName, pFunc) {
	if (IsNull(pElem)) { return; }

	if (pElem.addEventListener) {
		pElem.addEventListener(pEventBasicName, pFunc, false);
	}
	else {
		pElem.attachEvent("on" + pEventBasicName, pFunc);
	}
}


function AddLoadEvent(pFunc) {
	AddLoadEventObject(window, pFunc);
}


function AddLoadEventObject(pObject, pFunc) {
	AddFuncEvent(pObject, "load", pFunc);
}


function AddUnLoadEvent(pFunc) {
	AddUnLoadEventObject(window, pFunc)
}


function AddUnLoadEventObject(pObject, pFunc) {
	AddFuncEvent(pObject, "unload", pFunc);
}


function AddBeforeUpdateEvent(pFunc) {
	AddBeforeUpdateEventObject(window, pFunc)
}


function AddBeforeUpdateEventObject(pObject, pFunc) {
	AddFuncEvent(pObject, "beforeupdate", pFunc);
}


function AddResizeWindowEvent(pFunc) {
	AddResizeEventObject(window, pFunc);
}


function AddResizeDocumentEvent(pFunc) {
	AddResizeEventObject(document, pFunc);
}


function AddResizeEventObject(pObject, pFunc) {
	AddFuncEvent(pObject, "resize", pFunc);
}


function AddScrollEvent(pFunc) {
	AddScrollEventObject(window, pFunc);
}


function AddScrollEventObject(pObject, pFunc) {
	AddFuncEvent(pObject, "scroll", pFunc);
}

function AddEndRequest(pFunc) {
	if (typeof (Sys) != "undefined") { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(pFunc); }
}


function GetSize(pElem) {
	return {
		Height: $('#' + pElem.id).outerHeight(),
		Width: $('#' + pElem.id).outerWidth()
	};
}


function GetWindowDimensions() {

	return {
		Height: $(window).height(),
		Width: $(window).width()
	};
}


function GetDocumentDimensions(pDoc) {
	if (!IsNull(pDoc)) {
		return {
			Height: (IsIE ? pDoc.body.scrollHeight : pDoc.documentElement.offsetHeight),
			Width: $(pDoc).width()
		};
	}
	else {
		return {
			Height: (IsIE ? document.body.scrollHeight : document.documentElement.offsetHeight),
			Width: $(document).width()
		};
	}
}


// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function GetCookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';

	for (i = 0; i < a_all_cookies.length; i++) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split('=');


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if (cookie_name == check_name) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if (a_temp_cookie.length > 1) {
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) {
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function SetCookie(name, value, expiresMS, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if (IsNull(expiresMS)) {
		expiresMS = 1 * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date(today.getTime() + (expiresMS));

	document.cookie = name + "=" + escape(value) +
		((expiresMS) ? ";expires=" + expires_date.toGMTString() : "") + 
		";path=" + (path ? path : "/") +
		";domain=" + document.domain +
		((secure) ? ";secure" : "");
}

// this deletes the cookie when called
function DeleteCookie(name, path, domain) {
	if (GetCookie(name)) {
		SetCookie(name, '', 0, path, domain);
	}
}


function CenterByID(pID, pDoFull, pzIndex, pMaxWidth, pMaxHeight) {
	var element = document.getElementById(pID);
	var topDif;

	if (!IsNull(element)) {
		Show(element, pzIndex);

		var viewport = GetWindowDimensions();
		var dim = GetSize(element);


		if (top.window.innerHeight < viewport.Height) {
			viewport.Height = top.window.innerHeight;
		}

		if (ScrollTopTop() < ScrollIframeContainer()) {
			viewport.Height -= ScrollIframeContainer();
		}


		if (!IsNull(pMaxWidth)) {
			element.style.maxWidth = pMaxWidth;
		}

		if (!IsNull(pMaxHeight)) {
			element.style.maxHeight = pMaxHeight;
		}

		element.style.position = 'absolute';
		element.style.left = '50%';
		element.style.marginLeft = '-' + Math.floor(dim.Width / 2) + 'px';

		if (dim.Height > viewport.Height) {
			topDif = ScrollTop();
		}
		else {
			topDif = (ScrollTop() + ((viewport.Height - dim.Height) / 2)) - (ScrollIframeContainer() / 2);
		}

		if (topDif < 0) { topDif = 0; }

		element.style.top = topDif + 'px';
	}
}


function ScrollLeft() {
	return
	ScrollFilterResults(
		top.window.pageXOffset ? top.window.pageXOffset : 0,
		top.document.documentElement ? top.document.documentElement.scrollLeft : 0,
		top.document.body ? top.document.body.scrollLeft : 0
	) +
	ScrollFilterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}


function IsNotSameParent() {
	return (parent.location != location);
}


function ScrollIframeContainer() {
	if (!IsNotSameParent ()) {
		return 0;
	}
	else {
		return GetXY(parent.frames[window.name].frameElement).Y;
	}
}


function ScrollTopTop() {
	return ScrollFilterResults(
		top.window.pageYOffset ? top.window.pageYOffset : 0,
		top.document.documentElement ? top.document.documentElement.scrollTop : 0,
		top.document.body ? top.document.body.scrollTop : 0);
}


function ScrollTop() {

	var result = ScrollTopTop();

	result += ScrollFilterResults(
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0);

	return result;
}


function ScrollFilterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function SetHeightByID(pID, pHeight) {
	var element = document.getElementById(pID);

	if (!IsNull(element)) {
		element.style.height = pHeight + 'px';
	}
}


function SetWidthByID(pID, pHeight) {
	var element = document.getElementById(pID);

	if (!IsNull(element)) {
		element.style.width = pHeight + 'px';
	}
}


function SetZIndex(pID, pHeight) {
	var element = document.getElementById(pID);

	if (!IsNull(element)) {
		element.style.zIndex = pHeight + 'px';
	}
}


function ClearHeightByID(pID, pHeight) {
	var element = document.getElementById(pID);

	if (!IsNull(element)) {
		element.style.height = '';
	}
}


function ClearWidthByID(pID, pHeight) {
	var element = document.getElementById(pID);

	if (!IsNull(element)) {
		element.style.width = '';
	}
}


function ClearZIndex(pID, pHeight) {
	var element = document.getElementById(pID);

	if (!IsNull(element)) {
		element.style.zIndex = '0';
	}
}


function CreateDIV(pDivID) {
	return CreateElement('div', pDivID);
}


function CreateElement(pElementTag, pID) {
	return CreateElementInDoc(document, pElementTag, pID)
}


function CreateElementInDoc(pDoc, pElementTag, pID) {
	var eleP;


	eleP = pDoc.getElementById(pID);

	if (IsNull(eleP)) {
		eleP = pDoc.createElement(pElementTag);

		eleP.id = pID;

		pDoc.body.appendChild(eleP);
	}

	return eleP;
}



function GetApplicableWindowHeight() {
	var viewportheight = 0;

	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	}
	else {
		viewportheight = document.documentElement.clientHeight;
	}

	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		return viewportheight;
	}
	else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			return document.body.parentNode.clientHeight;
		}

		else {
			return document.body.parentNode.scrollHeight;
		}
	}
}


function MaximizeDivByID(pID, pzIndex) {
	var b = document.getElementById(pID);

	if (!IsNull(b)) {
		Show(b, pzIndex);
		b.style.height = GetApplicableWindowHeight() + 'px';
		b.style.width = '100%';
	}
}


function ShowToolTip(pContainerID, pCssClass, pContents) {
	var divToolTip = document.getElementById(DIVTOOLTIPID);
	var container = document.getElementById(pContainerID);
	var XY = GetXY(container);
	var containerSize = GetSize(container);

	divToolTip.className = pCssClass;

	divToolTip.style.position = "fixed";

	divToolTip.style.left = (XY.X + 4) + 'px';

	divToolTip.style.top = (container.offsetTop + (containerSize.Height / 2)) + 'px';

	divToolTip.innerHTML = pContents;

	Show(divToolTip, 1);
}


function HideToolTip() {
	HideByID(DIVTOOLTIPID);
}


function ToStringMS(pMilliseconds) {

	if (isNaN(pMilliseconds)) { pMilliseconds = 0; }

	// Milisegundos
	if (pMilliseconds <= 1000) {
		return parseFloat(pMilliseconds).toFixed(2) + "ms";
	}
	// Segundos
	else if (pMilliseconds <= 60000) {
		return parseFloat(pMilliseconds / 1000.0).toFixed(2) + "s";
	}
	// Minutos
	else if (pMilliseconds <= 3600000) {
		return parseFloat(pMilliseconds / 60000.0).toFixed(2) + "m";
	}

	// Horas			
	return parseFloat(pMilliseconds / (60000 * 24.0)).toFixed(2) + "h";
}


function DateDiff(dateStart, dateEnd) {
	if (IsNull(dateEnd)) {
		dateEnd = new Date();
	}
	if (typeof (dateStart) == "String" || typeof (dateStart) == "string") {
		dateStart = new Date(dateStart);
	}
	if (IsNull(dateStart)) {
		return 0;
	}
	
	return dateEnd.getTime() - dateStart.getTime();
}


function DateDiffSeconds(pStart, pEnd) {
	return DateDiff(pStart, pEnd) / 1000;
}


function HideLoadingMessage() {

	try {
		// No es la pagina principal
		if (top.location != location) {
			top.HideLoadingMessage();
		}
	}
	catch (err) { }

	HideByID(DIVLOADINGMESSAGEID + '_Container');

	HideByID(DIVLOADINGMESSAGEID);

	SetIsLoadingMessage(false);
}


var blnShowLoadingMessage = false;


function IsShowingLoadingMessage() {
	try {

		return parent.blnShowLoadingMessage;
	}
	catch (err) {

		return false;
	}
}


function SetIsLoadingMessage(pValue) {
	try {
		blnShowLoadingMessage = pValue;
		parent.blnShowLoadingMessage = pValue;
	}
	catch (err) { }
}


function ShowLoadingMessage() {

	if (!IsShowingLoadingMessage()) {

		// NO es la principal, se invoca la principal (y no es un iframe de carga de archivo)
		if (top.location != location && location.toString().indexOf('AsyncFileUploadID') == -1) {
			try { top.ShowLoadingMessage(); } catch (err) { }
			return;
		}
		else {
			SetIsLoadingMessage(true); MaximizeDivByID(DIVLOADINGMESSAGEID + '_Container', 13000); CenterByID(DIVLOADINGMESSAGEID, true, 13001);
		}

	}
}


ShowLoadingMessage();


if (typeof (esf_oldstyles_showoverbyid) == "undefined") {
	esf_oldstyles_showoverbyid = new Array();
}


ShowOverByIDIframe = function (pURL, pWidth, pHeight, pAllowScrolling) {
	var iframe = document.getElementById(IFRAMEPOPUP);
	var windim = GetWindowDimensions();

	if (!pWidth) {
		pWidth = windim.Width * 0.9;
	}

	if (!pHeight) {
		pHeight = windim.Height * 0.9;
	}

	iframe.style.width = pWidth + 'px';
	iframe.style.height = pHeight + 'px'


	if (IsNull(pAllowScrolling)) {
		iframe.scrolling = "yes";
	}
	else {
		iframe.scrolling = (pAllowScrolling ? "yes" : "no");
	}

	ShowOverByID(iframe.id, false);

	iframe.src = pURL;
}


HideOverByIDIframe = function () {
	HideOverByID(IFRAMEPOPUP, false);
}


var esf_ShowOverByID_ID;


GetSizeOverByID = function () {
	if (IsVisibleByID(esf_ShowOverByID_ID)) {
		return GetSize(document.getElementById(esf_ShowOverByID_ID));
	}
	else {
		return { Height: 0, Width: 0 };
	}
}


ShowOverByID = function (pID, pSaveCurrentStyle, pMaxWidth, pMaxHeight) {

	MaximizeDivByID(DIVCOVERID, 11000);

	esf_ShowOverByID_ID = pID;

	if (pSaveCurrentStyle) {
		var element = document.getElementById(pID);

		if (!IsNull(element)) {

			esf_oldstyles_showoverbyid[pID] = new Array();
			esf_oldstyles_showoverbyid[pID] =
				{ position: element.style.position,
					left: element.style.left,
					top: element.style.top,
					display: element.style.display,
					float: element.style.float,
					zIndex: element.style.zIndex,
					marginLeft: element.style.marginLeft
				};
		}
	}

	ShowByID(DIVCOVERID);

	CenterByID(pID, false, 11001, pMaxWidth, pMaxHeight);

	FixContentSizes($('#' + pID).height());
}


HideOverByID = function (pID, pRestoreOldStyle) {

	HideByID(DIVCOVERID);
	HideByID(pID);

	if (pRestoreOldStyle) {
		var element = document.getElementById(pID);
		if (!IsNull(element) && !IsNull(esf_oldstyles_showoverbyid[pID])) {

			element.style.position = esf_oldstyles_showoverbyid[pID].position;
			element.style.left = esf_oldstyles_showoverbyid[pID].left;
			element.style.top = esf_oldstyles_showoverbyid[pID].top;
			element.style.display = esf_oldstyles_showoverbyid[pID].display;
			element.style.float = esf_oldstyles_showoverbyid[pID].float;
			element.style.zIndex = esf_oldstyles_showoverbyid[pID].zIndex;
			element.style.marginLeft = esf_oldstyles_showoverbyid[pID].marginLeft;
		}
	}

	HideByID(DIVCOVERID);
}


EnableByID = function (pID) {
	EnableDisableByID(pID, true);
}

DisableByID = function (pID) {
	EnableDisableByID(pID, false);
}

EnableDisableByID = function (pID, pBoolValue) {
	var control = document.getElementById(pID);
	if (!IsNull(control)) {

		control.disabled = !pBoolValue;
	}
}


InitializeAJAXHandler = function () {
	if (typeof (Sys) != 'undefined' && Sys != null) {
		var ajaxIns;


		ajaxIns = Sys.WebForms.PageRequestManager.getInstance();

		ajaxIns.add_beginRequest(CustomBeginRequestHandler);
		ajaxIns.add_endRequest(CustomEndRequestHandler);
	}
}


var blnAlreadyAddedLoading = true;



function CustomBeginRequestHandler(sender, args) {
	var control;

	SetLastRequestDateTime();


	ShowLoadingMessage();

	control = args.get_postBackElement();

	if (!IsNull(control) && !IsNull(control.id) && !IsNull(control.type)) {
		if (control.type.toString().toUpperCase() != "FILE") {
			control.disabled = true;

			control.oldValue = $('#' + control.id).val();

			$('#' + control.id).val('Procesando...');
		}
	}
}


function CustomEndRequestHandler(sender, args) {
	var control;

	HideLoadingMessage();

	control = sender._postBackSettings.sourceElement;

	if (!IsNull(control) && !IsNull(control.id) && !IsNull(control.oldValue) && !IsNull(control.type)) {
		control.disabled = false;

		$('#' + control.id).val(control.oldValue);
	}
}


var esf_totalerrors = 0;


function CustomHandleError(err, url, line) {
	var mensaje;
	var temp;


	if (esf_totalerrors == 0) {
		temp = new String(err);

		// Es un error descartable (debido al manejo de foco sobre un componente no visible en IE
		if (temp.indexOf('focus') != -1) {
			return true;
		}

		// Se ajusta el mensaje
		else if (temp.length >= 29 && temp.substring(0, 29) == 'Sys.InvalidOperationException') {
			temp = window.status = temp.substring(31, temp.length);
			alert(temp);
		}

		else if (temp.length >= 51 && temp.substring(0, 51) == 'Sys.WebForms.PageRequestManagerServerErrorException') {
			temp = window.status = temp.substring(53, temp.length);
			alert(temp);
		}
	}

	HideLoadingMessage();

	esf_totalerrors++;

	// TODO: Reportar via web mediante REST

	return false;
}


SetLastRequestDateTime = function () {
	SetCookie('esf_LastRequestDateTime', new Date());
}

SetLastRequestDateTime();

GetLastRequestDateTime = function () {
	GetCookie('esf_LastRequestDateTime');
}


SetLastUserMovementDateTime = function () {
	SetCookie('esf_LastUserMovementDateTime', new Date());
}

SetLastUserMovementDateTime();

GetLastUserMovementDateTime = function () {
	return GetCookie('esf_LastUserMovementDateTime');
}


CustomHandleLoad = function () {
	InitializeAJAXHandler();

	if (typeof (ShowContents) != "undefined") {
		ShowContents();
	}

	HideLoadingMessage();

	AddScrollEvent(SetLastUserMovementDateTime);

	$(document).mousemove(SetLastUserMovementDateTime);
}


CancelScroll = function () {
	window.onscroll = function (event) {
		scrollTo(0, 0);
	};
}


GoTop = function (pURL) {
	top.location = pURL;
}


GoTopFrame = function (pFrameName, pURL) {
	top.frames[pFrameName].location = pURL;
}


GoParentFrame = function (pFrameName, pURL) {
	parent.frames[pFrameName].location = pURL;
}


PreloadImage = function (pURL) {
	if (document.images) {
		var pic = new Image();
		pic.src = pURL;
	}
}



function GetXYByID(pID) {
	return GetXY(document.getElementById(pID));
}


function GetXY(e) {

	var curleft = 0;
	var curtop = 0;

	do {
		curleft += e.offsetLeft;
		curtop += e.offsetTop;

		e = e.offsetParent;
	} while (!IsNull(e));

	return { X: curleft, Y: curtop };
}


CustomHandleAbort = function () {
	alert("La carga de la página no ha sido completada.\nEsto impide el normal funcionamiento de la página, debe recargarla");
}

AddLoadEvent(CustomHandleLoad);

AddUnLoadEvent(ShowLoadingMessage);


window.onerror = CustomHandleError;

window.onabort = CustomHandleAbort;


var esfShowLoadingMessage_IsEnabled = true;

window.onbeforeunload = function () {
	if (esfShowLoadingMessage_IsEnabled == true) {
		ShowLoadingMessage();
	}
}


function WebForm_FireDefaultButton(event, target) {

	if ((typeof (__defaultFired) == "undefined" || !__defaultFired) && event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
		var defaultButton;
		if (__nonMSDOMBrowser)
			defaultButton = document.getElementById(target);
		else
			defaultButton = document.all[target];

		if (typeof (defaultButton.click) != "undefined") {
			__defaultFired = true;
			defaultButton.click();
			event.cancelBubble = true;

			if (event.stopPropagation) event.stopPropagation();
			return false;
		}

		if (typeof (defaultButton.href) != "undefined") {
			__defaultFired = true;
			eval(defaultButton.href.substr(11));
			event.cancelBubble = true;

			if (event.stopPropagation) event.stopPropagation();
			return false;
		}

	}
	return true;
}


function GetDocHeight() {

	try {
		return IsIE ? document.body.scrollHeight : document.documentElement.offsetHeight;
	}
	catch (ex) { return 0; }
}


addStyle = function (pClassName, pDefinition) {
	var style = $('<style>' + pClassName + " { " + pDefinition + '; }</style>');


	$('html > head').append(style);

	// This may or may not work in IE, however you can use IE's proprietary addRule instead:
	if (IsIE) {
		document.styleSheets[0].addRule(pClassName, pDefinition, -1);
	}
}


fixDivs = function () {
	var trashDivs;
	var otherTrashDivs;
	var temp;
	var tempFChild;


	trashDivs = $('table[class^="grvGrid"]');

	for (var i = 0; i < trashDivs.length; i++) {
		$('#' + trashDivs[i].id).parent().css('width', '100%');
	}


	otherTrashDivs = $('div[id^="ctl00_" ]');

	for (var i = 0; i < otherTrashDivs.length; i++) {
		temp = $('#' + otherTrashDivs[i].id);

		tempFChild = temp.find(':first');


		if (typeof (temp.attr('class')) == "undefined"
			&& typeof (temp.attr('style')) == "undefined"
			&& typeof (tempFChild) != "undefined") {
			if (typeof (tempFChild.attr('id')) == "undefined" ||
				tempFChild.attr('id').indexOf("QueryOrderbyShowParams") == -1) {
				addStyle('#' + otherTrashDivs[i].id, 'width: 100%');
			}
		}
	}


	otherTrashDivs = $('div[id^="cntContenido_"]');

	for (var i = 0; i < otherTrashDivs.length; i++) {
		temp = $('#' + otherTrashDivs[i].id);

		tempFChild = temp.find(':first');


		if (typeof (temp.attr('class')) == "undefined"
			&& typeof (temp.attr('style')) == "undefined"
			&& typeof (tempFChild) != "undefined") {
			if (typeof (tempFChild.attr('id')) == "undefined" ||
				tempFChild.attr('id').indexOf("QueryOrderbyShowParams") == -1) {
				addStyle('#' + otherTrashDivs[i].id, 'width: 100%');
			}
		}
	}
};


FixContentSizes = function (pReallyHeight) {

	showOverByID_Size = GetSizeOverByID();

	if (typeof (pReallyHeight) != "undefined" && isNaN(pReallyHeight) && showOverByID_Size.Height > 0) {
		if (pReallyHeight < showOverByID_Size.Height) {
			pReallyHeight = showOverByID_Size.Height;
		}
	}
	else if (showOverByID_Size.Height > 0) {
		pReallyHeight = showOverByID_Size.Height;
	}

	if (IsNotSameParent() && typeof (parent.FixSizeContentsIframeOnload) != "undefined") {
		parent.FixSizeContentsIframeOnload(pReallyHeight);
	}
}


$(document).ready(fixDivs);


$(document).ready(
	function () {
		AddEndRequest(
			function () {
				fixDivs();
				FixContentSizes();
			});

		AddResizeDocumentEvent(FixContentSizes);

		$(document).click(FixContentSizes);
	}
);


RequestGET = function (pUseTop) {
	if (pUseTop) {
		this.QueryString = top.window.location.search;
	}
	else {
		this.QueryString = window.location.search;
	}

	if (this.QueryString.length > 1) { this.QueryString = this.QueryString.substring(1, this.QueryString.length); }
	else { this.QueryString = null; }

	this.keyValuePairs = new Array();


	if (this.QueryString) {
		for (var i = 0; i < this.QueryString.split("&").length; i++) {
			this.keyValuePairs[i] = this.QueryString.split("&")[i];
		}
	}


	this.GetKeyValuePairs = function () { return this.keyValuePairs; }


	this.GetValue = function (s, valueIfNull) {
		for (var j = 0; j < this.keyValuePairs.length; j++) {
			if (this.keyValuePairs[j].split("=")[0] == s) {
				return unescape(this.keyValuePairs[j].split("=")[1]);
			}
		}

		if (!IsNull(valueIfNull)) {
			return valueIfNull;
		}

		return "";
	}


	this.GetValueID = function (s) { return this.GetValue(s, -1); }


	this.GetValueBool = function (s) { return (new String(this.GetValue(s, false)).toUpperCase() == "TRUE"); }


	this.GetParameters = function () {
		var a = new Array(this.GetLength());

		for (var j = 0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}

		return a;
	}

	this.GetLength = function () { return this.keyValuePairs.length; }
}


function CustomParseFloat(pValue) {

	if (IsNullOrEmpty(pValue)) { return 0; }
	else {
		return parseFloat(pValue.toString().replace('/\\$|\\' + CurrencyGroupSeparator + '/g', '').replace(CurrencyDecimalSeparator, '.'));
	}
}


function FormatCurrency(strValue) {
	if (IsNullOrEmpty(strValue)) { return CurrencySymbol + ' 0' + CurrencyDecimalSeparator + '00'; }
	else {

		dblValue = CustomParseFloat(strValue);

		blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
		dblValue = Math.floor(dblValue * 100 + 0.50000000001);
		intCents = dblValue % 100;
		strCents = intCents.toString();
		dblValue = Math.floor(dblValue / 100).toString();
		if (intCents < 10)
			strCents = "0" + strCents;
		for (var i = 0; i < Math.floor((dblValue.length - (1 + i)) / 3); i++)
			dblValue = dblValue.substring(0, dblValue.length - (4 * i + 3)) + CurrencyGroupSeparator +
			dblValue.substring(dblValue.length - (4 * i + 3));

		return (((blnSign) ? '' : '-') + CurrencySymbol + ' ' + dblValue + CurrencyDecimalSeparator + strCents);
	}
}